from set_tool import Right_UI
import sys, base64, sip
import qtawesome, requests, re
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor, QImage, QPixmap
from PyQt5.QtWidgets import QColorDialog,QFontDialog
from io import BytesIO
import requests,re
from fake_useragent import UserAgent

class right_img(Right_UI):
    def right_img_get(self):
        self.imag_url,self.iico=[],[]
        ua=UserAgent()
        #headers = {'User-Agent': ua.random}
        url = 'https://www.qidian.com/rank/yuepiao?page=1'
        try:
            headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
            }
            html = requests.get(url, headers=headers)
            if html.status_code == 200:
                #print(html.text)
                pattern = re.compile('<li data-rid.*?>[\s\S.]*?<span class=.*?>(.*?)<cite>[\s\S.]*?<h4><a href="(.*?)".*?data-bid=.*?>(.*?)</a>'
                                     '</h4>[\s\S]*?<p class="author">[\s\S]*?<img.*?data-eid=.*?>(.*?)</a>' ,re.S)

                self.imag = re.findall(r'data-bid=".*?"><img src="(.*?)"></a>', html.text, re.S)
                yuepiao = re.findall(r'[0-9]{0,}[0-9]{0,}[0-9]{0,}[.|0-9]{0,}[.|0-9]{1,}[万月票]{2,}', html.text, re.S)
                zishu = re.findall(r'[0-9]{0,}[0-9]{0,}[0-9]{0,}[.|0-9]{0,}[.|0-9]{1,}[万]{0,}[字]{1,}', html.text, re.S)
                self.jianjie = re.findall('<li data-rid.*?>[\s\S.]*?<p class="intro">[\s\S.](.*?)</p>', html.text, re.S)
                #print(self.imag)
                #print(yuepiao)
                #print(zishu)
                #print(self.jianjie)
                self.items = re.findall(pattern, html.text)
                print(self.items)
                for i in self.imag:
                    i='https:'+i
                    self.imag_url.append(i)
                for url in self.imag_url:
                    req = requests.get(url)
                    self.iico.append(req.content)
        except:
            pass

        #print(a.text)
        """imag=re.findall(r'<img src=".*?" data-src="(.*?)" class="book-cover" alt="(.*?)">',html.text,re.S)
        yuepiao=re.findall(r'[0-9]{0,}[0-9]{0,}[0-9]{0,}[.|0-9]{0,}[.|0-9]{1,}[万月票]{2,}',html.text,re.S)
        zishu=re.findall(r'[0-9]{0,}[0-9]{0,}[0-9]{0,}[.|0-9]{0,}[.|0-9]{1,}[万]{0,}[字]{1,}',html.text,re.S)
        jianjie=re.findall(r'<p class="book-desc">(.*?)</p>',a.text,re.S)
        zuozhe=re.findall(r'<span class="book-author">[\s\S.]*?</use></svg>(.*?)[\s\S.]*?</span>',html.text,re.S)
        print(imag[0:-1])
        print(yuepiao)
        print(zishu)
        print(jianjie[0:-1])
        print(zuozhe[0:-1])"""



